package spring.board.service;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import spring.board.dao.MainDao;

public class MemberService implements UserDetailsService{
	private MainDao mainDao;
	
	public void setMainDao(MainDao mainDao) {
		this.mainDao = mainDao;
	}

	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {

		// 로그인 아이리도 패스워드를 가지고 온다.
		String pwd = mainDao.getPwd(username);
		
		// "ROLE_USER"라는 이름으로 권한을 설정한다.
		Collection<SimpleGrantedAuthority> roles = new ArrayList<SimpleGrantedAuthority>();
		//roles.add(new Simple)
		
		// 로그인 정보를 리턴한다.
		UserDetails user = new User(username, pwd, roles);
		return user;
	}
	
}
